package com.lile.array;

public class ArraySort {

	public static void main(String[] args) {

		// 将字符串中的字符进行排序
		String s = "htgrafkrgfefe";
		char[] chs = s.toCharArray();
		bubbleSort(chs);
		String result = String.valueOf(chs);
		System.out.println(result);

		// 定义数组
		int[] arr = { 24, 69, 80, 57, 13 };

		selectSort(arr);
		printArray(arr);
	}

	public static void printArray(int[] arr) {
		System.out.print("[");
		for (int x = 0; x < arr.length; x++) {
			if (x == arr.length - 1) {
				System.out.print(arr[x]);
			} else {
				System.out.print(arr[x] + ", ");
			}
		}
		System.out.println("]");
	}

	public static void bubbleSort(char[] arr) {
		for (int i = 0; i < arr.length - 1; i++) {
			for (int j = 0; j < arr.length - 1 - i; j++) {
				if (arr[j] > arr[j + 1]) {
					char temp = arr[j];
					arr[j] = arr[j + 1];
					arr[j + 1] = temp;
				}
			}
		}
	}

	public static void selectSort(int[] arr) {
		for (int i = 0; i < arr.length - 1; i++) {
			for (int j = i + 1; j < arr.length; j++) {
				if (arr[j] < arr[i]) {
					int temp = arr[i];
					arr[i] = arr[j];
					arr[j] = temp;
				}
			}
		}
	}

}
